<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\common\model;

/**
 * 活动模型
 */
class Active extends ModelBase
{
    protected $insert = ['create_time'];

    public function getImageAttr(){
        return get_picture_url($this->cover_id,false);
    }




    /**
     * 连用户表
     */
    public function user(){
        return $this->belongsTo('Member','member_id','id');
    }

    /**
     * 关联门票表
     */
    public function ticket(){
        return $this->hasMany('ActiveTicket','active_id','id');
    }


    public function  getKing(){

        if($this->tags){
            $tags=rtrim($this->tags, ",");
            $tags=ltrim($tags, ",");
            $tags=explode(',',$tags);
            //dd(GamblerKing::all(['status'=>1,'id'=>['in',$tags]]));
            $list=GamblerKing::all(['status'=>1,'id'=>['in',$tags]]);
            foreach ($list as $k=>$v){
                $list[$k]['tags_name']=$v->tags_name;
                $list[$k]['image']=$v->image;
            }
            return $list;
        }else{
            return [];
        }
    }

    /**
     * 时间自动完成
     */
    public function setCreateTimeAttr()
    {

        return TIME_NOW;
    }


    /**
     * 标签数组
     */
    public function getTagsArrayAttr(){
        if($this->tags){
            $tags=rtrim($this->tags, ",");
            $tags=ltrim($tags, ",");
            return explode(',',$tags);
        }else{
            return [];
        }

    }


    /**
     * 标签数组
     */
    public function getTagsNameAttr(){
        if($this->tags){
            $list=GamblerKing::column('name','id');

            $tags=rtrim($this->tags, ",");
            $tags=ltrim($tags, ",");
            $tags=explode(',',$tags);
            $tag='';
            foreach ($tags as $k=>$v){
                if($k==0){
                    $tag.=$list[$v];
                }else{
                    $tag.=','.$list[$v];
                }
            }
            return $tag;
//            $lang=isset($_REQUEST['lang'])?$_REQUEST['lang']:'';
//            return   baidu_translate($tag,$lang);
        }else{
            return '';
        }

    }
//    public function  getNameAttr($value){
//
//        $lang=isset($_REQUEST['lang'])?$_REQUEST['lang']:'';
//        return   baidu_translate($value,$lang);
//
//    }


//    public function  getDescribeAttr($value){
//        $lang=isset($_REQUEST['lang'])?$_REQUEST['lang']:'';
//        return   baidu_translate($value,$lang);
//
//    }
//
//    public function  getContentAttr($value){
//        $lang=isset($_REQUEST['lang'])?$_REQUEST['lang']:'';
//        return   baidu_translate($value,$lang);
//
//    }
    /**
     * 时间获取器
     */
    public function getCreateTimeAttr($value)
    {

        return date('Y-m-d H:i:s',$value);
    }



}
